<%@ tag language="java" pageEncoding="UTF-8" trimDirectiveWhitespaces="true"%>
<%@ include file="/WEB-INF/views/utils/includes.jsp"%>
<%@ attribute name="value" required="true" rtexprvalue="true"%>
<%@ attribute name="required" type="java.lang.Boolean" required="false" rtexprvalue="true"%>
<%@ attribute name="regexValidation" type="java.lang.String" required="false" rtexprvalue="true"%>
<%@ attribute name="path" required="true" type="java.lang.String" rtexprvalue="false"%>
<%@ attribute name="editable" required="false" type="java.lang.Boolean" rtexprvalue="true"%>
<%@ attribute name="hidden" required="false" type="java.lang.Boolean" rtexprvalue="true"%>

<c:choose>
	<c:when test="${hidden}">
		<input type="hidden" id="${path}" name="${path}" value="${value}">
	</c:when>
	<c:when test="${editable}">
		<input type="text" id="${path}" name="${path}" value="${value}">
		<script type="text/javascript">
$(document).ready (
	function () {
		var elem = $("#${path}".replace('\\.', '\\\\\\\\.'));
		elem.parents("form").submit(
			function(e) {
				var value = elem.val();
<c:if test="${required}">
				if(value == null || value.length == 0) {
                    e.stopImmediatePropagation();
					alert('<tu:i18n value="form.validation.required"/>');
					elem.focus();
					return false;
				}
</c:if>
<c:if test="${regexValidation != null}">
				if(value && !value.match(/${regexValidation}/)) {
					e.stopImmediatePropagation();
					alert('<tu:i18n value="form.validation.invalid.format"/>')
					elem.select();
					return false;
				}
</c:if>
			}
		);
	}
);
</script>
	</c:when>
	<c:otherwise>
		<input type="hidden" id="${path}" name="${path}" value="${value}">${value}
	</c:otherwise>
</c:choose>
